package com.wyg.component;

import java.util.Iterator;

/**
 * @description:
 * @author: WYG
 * @time: 2021/4/6 9:19
 */

public class Waitress {
    private MenuComponent menuComponent;
    public Waitress(MenuComponent menuComponent) {
        this.menuComponent = menuComponent;
    }
    public void print() {
        menuComponent.print();
    }
    public void printVegetarianMenu() {
        Iterator<MenuComponent> iterator = menuComponent.createIterator();
        while (iterator.hasNext()) {
            MenuComponent next = iterator.next();
            try {
                if (next.isVegetarian()) {
                    next.print();
                }
            } catch (UnsupportedOperationException e) {

            }

        }
    }

    public static void main(String[] args) {
        MenuComponent pancakeHouseMenu = new Menu("pancakeHouseMenu0", "breakfast");
        MenuComponent dinerMenu = new Menu("dinerMenu", "lunch");
        MenuComponent cafeMenu = new Menu("cafeMenu", "dinner");
        MenuComponent dessertMenu = new Menu("dessertMenu", "dessert");
        MenuComponent allMenus = new Menu("all", "all");
        allMenus.add(pancakeHouseMenu);
        allMenus.add(dinerMenu);
        allMenus.add(cafeMenu);
        allMenus.add(dessertMenu);
        dinerMenu.add(new MenuItem("breakfast", "eggs", true, 2.99));
        dinerMenu.add(dessertMenu);
        dessertMenu.add(new MenuItem("apple pie", "apple with crust", true, 1.23));
        Waitress waitress = new Waitress(allMenus);
        waitress.print();
    }
}
